<?php
namespace app\api\controller;


use app\api\model\Goods;
use app\BaseController;
class GoodsController extends BaseController
{
	// 根据商品ID 获取到商品信息
	public function getGoodsByIds(Goods $model)
	{
		$goodsIds = $this->request->param('goodsIds/a',[]);
		if(empty($goodsIds)){
			return $this->returnJson('商品ID必须传递|11');
		}
		$goods = $model->where('id','in',$goodsIds)->with(['category','goodsImg'])->select();
		return $this->returnJson('ok',$goods,count($goods));
	}
	// 商品详情
	public function detail(Goods $model)
	{
		$goodsId = $this->request->param('goodsId',0);
		if($goodsId == 0){
			return $this->returnJson('商品ID必须传递|11');
		}
		$goods = $model->where('id',$goodsId)->with(['category','goodsImg'])->find();
		return $this->returnJson('ok',$goods,1);

	}

	// 商品分类列表
	public function lists(Goods $model)
	{

		$page = $this->request->param('page',1);

		$pageSize = $this->request->param('pageSize',10);

		$categoryId = $this->request->param('categoryId',0);

		if($categoryId == 0){
			return $this->returnJson('商品分类ID必须传递|10');
		}

		$goods  = $model->where('category_id',$categoryId)->with('category');

		return $this->returnJson(
			'ok',
			$goods->page($page,$pageSize)->select(),
			$goods->count()
		);
	}	
}